package com.giaothong.model.entity;

import org.json.JSONObject;

import com.giaothong.utils.JSONUtil;

/**
 * store distance and duration
 * 
 * @author hp
 */
public class DistanceEntity {
	private String text = ""; // store distance with km
	private int value; // store distance with m

	/**
	 * set & get mothod
	 * 
	 * @param distanceKm
	 */
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public int getValue() {
		return value;
	}

	/**
	 * column of item
	 */

	public static final String COLUMN_TEXT = "text";
	public static final String COLUMN_VALUE = "value";

	/**
	 * Unknown value of Item
	 */

	public final String UNKNOWN_TEXT = "0 km";
	public final int UNKNOWN_VALUE = 0;

	/**
	 * defaut contructor
	 */
	public DistanceEntity() {
		setDefaultValue();
	}

	/**
	 * contructor by JsonObject
	 * 
	 * @param jsonObject
	 */
	public DistanceEntity(JSONObject jsonObject) {
		setDefaultValue();
		if (jsonObject == null)
			return;

		this.text = JSONUtil.stringTryGetValue(jsonObject, COLUMN_TEXT);
		this.value = JSONUtil.intTryGetValue(jsonObject, COLUMN_VALUE);

	}

	/**
	 * set defaut value
	 */
	public void setDefaultValue() {
		this.text = UNKNOWN_TEXT;
		this.value = UNKNOWN_VALUE;
	}

}
